package com.gnerv.sylvanas.framework.common.tools;

import java.util.Random;

/**
 * <p>
 * 字符串 工具类
 * </p>
 *
 * @author Gnerv LiGen
 */
public class StringTools {

    private static final Random RANDOM = new Random();

    private StringTools() {
    }

    /**
     * 随机字符串 小写
     *
     * @param length 字符串长度
     */
    public static String random(int length) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int charInt = RANDOM.nextInt(26) + 97;
            stringBuilder.append((char) charInt);
        }
        return stringBuilder.toString();
    }

    public static String covering(String source, int length) {
        return covering(source, length, ' ');
    }

    /**
     * 补位
     *
     * @return 补位后的字符串
     */
    public static String covering(String source, int length, Character placeholder) {
        if (source == null) {
            return null;
        }
        if (placeholder == null) {
            placeholder = ' ';
        }
        if (source.length() >= length) {
            return source;
        }
        source = source + String.valueOf(placeholder).repeat(length - source.length());
        return source;
    }

    /**
     * %s 字符串类型
     * %b 布尔类型
     * %d 整数类型（十进制）
     *
     * @param format
     * @param args
     * @return
     */
    public static String format(String format, Object... args) {
        return String.format(format, args);
    }

    public static String upperCamelCase(String source) {
        StringBuilder stringBuilder = new StringBuilder();
        char[] charArray = source.toCharArray();
        for (char c : charArray) {
            if (c >= 'A' && c <= 'Z') {
                stringBuilder.append(String.valueOf(c).toLowerCase());
            }
            if (c == '_' || c == '-') {
                stringBuilder.append(String.valueOf(c).toUpperCase());
            }
        }


        return source;
    }

    public static String lowerCamelCase(String source) {
        return source;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(covering("sa", 4, '-'));
        }
    }
}
